﻿<Page x:Class="BulletDemo1.Page1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:BulletDemo1"
    xmlns:bullet="clr-namespace:XnaDevRu.Bullet.Dynamics"
    xmlns:primitive="clr-namespace:Primitive3DSurfaces;assembly=Primitive3DSurfaces" 
    Title="Page1"
    >

  <Page.Resources>
    <local:World x:Key="world"/>
    <primitive:Sphere3D x:Key="sphere">
      <primitive:Sphere3D.Material>
        <MaterialGroup>
          <DiffuseMaterial>
            <DiffuseMaterial.Brush>
              <ImageBrush ImageSource="BeachBallColor.jpg"/>
            </DiffuseMaterial.Brush>
          </DiffuseMaterial>
          <SpecularMaterial Brush="White" SpecularPower="50"/>
        </MaterialGroup>
      </primitive:Sphere3D.Material>
      <primitive:Sphere3D.Transform>
        <ScaleTransform3D ScaleX="0.5" ScaleY="0.5" ScaleZ="0.5"/>
      </primitive:Sphere3D.Transform>
    </primitive:Sphere3D>

    <ModelVisual3D x:Key="box">
      <ModelVisual3D.Content>
        <GeometryModel3D>
          <GeometryModel3D.Geometry>
            <MeshGeometry3D
              Positions="-0.5,-0.5,0.5 -0.5,0.5,0.5    0.5,0.5,0.5   0.5,-0.5,0.5
                         -0.5,0.5,0.5   -0.5,0.5,-0.5  0.5,0.5,-0.5  0.5,0.5,0.5
                         -0.5,0.5,-0.5  -0.5,-0.5,-0.5 0.5,-0.5,-0.5 0.5,0.5,-0.5
                         -0.5,-0.5,-0.5 -0.5,-0.5,0.5  0.5,-0.5,0.5  0.5,-0.5,-0.5
                         -0.5,-0.5,-0.5 -0.5,0.5,-0.5  -0.5,0.5,0.5  -0.5,-0.5,0.5
                         0.5,-0.5,0.5   0.5,0.5,0.5    0.5,0.5,-0.5  0.5,-0.5,-0.5"
              Normals="0,0,1 0,0,1 0,0,1 0,0,1
                       0,1,0  0,1,0  0,1,0  0,1,0
                       0,0,-1  0,0,-1  0,0,-1  0,0,-1
                       0,-1,0 0,-1,0 0,-1,0 0,-1,0
                       -1,0,0 -1,0,0 -1,0,0 -1,0,0
                       1,0,0  1,0,0  1,0,0  1,0,0"
              TriangleIndices="2,1,0 0,3,2 6,5,4 4,7,6 10,9,8 8,11,10 14,13,12 12,15,14 18,17,16 16,19,18 22,21,20 20,23,22"/>
          </GeometryModel3D.Geometry>
        </GeometryModel3D>
      </ModelVisual3D.Content>
    </ModelVisual3D>

  </Page.Resources>

  <Grid>

    <Viewport3D Name="viewport" IsHitTestVisible="False" ClipToBounds="False">

      <Viewport3D.Camera>
        <PerspectiveCamera x:Name="camera" Position="0,0,10" LookDirection="0,0,-1" FieldOfView="60"/>
      </Viewport3D.Camera>

      <ModelVisual3D x:Name="light">
        <ModelVisual3D.Content>
          <Model3DGroup>
            <AmbientLight Color="#505050"/>
            <DirectionalLight Color="#A0A0A0" Direction="0,0,-1" />
          </Model3DGroup>
        </ModelVisual3D.Content>
      </ModelVisual3D>

      <ModelVisual3D>
        <ModelVisual3D.Content>
          <GeometryModel3D x:Name="sphereGeometry">
            <GeometryModel3D.Material>
              <DiffuseMaterial>
                <DiffuseMaterial.Brush>
                  <ImageBrush ImageSource="BeachBallColor.jpg"/>
                </DiffuseMaterial.Brush>
              </DiffuseMaterial>
            </GeometryModel3D.Material>
          </GeometryModel3D>
        </ModelVisual3D.Content>
      </ModelVisual3D>

      <ModelVisual3D>
        <ModelVisual3D.Content>
          <GeometryModel3D x:Name="boxGeometry">
            <GeometryModel3D.Material>
              <DiffuseMaterial>
                <DiffuseMaterial.Brush>
                  <ImageBrush ImageSource="BeachBallColor.jpg"/>
                </DiffuseMaterial.Brush>
              </DiffuseMaterial>
            </GeometryModel3D.Material>
          </GeometryModel3D>
        </ModelVisual3D.Content>
      </ModelVisual3D>

    </Viewport3D>

    <Border Name="captureBorder" Background="Transparent" Grid.Row="0" Grid.Column="0" Focusable="True" />

    <Canvas>
      <StackPanel Canvas.Right="50" Canvas.Bottom="50">
        <Button Click="dropSphere_Click">Drop sphere</Button>
        <Button Click="dropBox_Click">Drop box</Button>
      </StackPanel>
    </Canvas>

  </Grid>

</Page>
